<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>使用props传递数据</title>
</head>

<body>
    <div id="app1">
        <my-component message="来自父组件的数据"></my-component>
    </div>
    <div id="app2">
        <input type="text" v-model="parentMessage">
        <my-component :message="parentMessage"></my-component>
    </div>
    <!-- 单向数据流 -->
    <div id="app3">
        <my-component :init-count="1"></my-component>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        Vue.component('my-component', {
            props: ['message'],
            template: '<div>{{message}}</div>'
        })
        var app1 = new Vue({
            el: '#app1'
        })

        Vue.component('my-component', {
            props: ['message'],
            template: '<div>{{message}}</div>'
        })
        var app2 = new Vue({
            el: '#app2',
            data: {
                parentMessage: ''
            }
        })

        Vue.component('my-component', {
            props: ['initCount'],
            template: '<div>{{count}}</div>',
            data: function () {
                return {
                    count: this.initCount
                }
            }
        })
        var app3 = new Vue({
            el: '#app3'
        })
    </script>
</body>

</html>